/*!
 * @file Manager.cpp
 * @author naoki takeda
 * @
 */
#include "StdAfx.h"
#include "NTEngine/Core/Core.h"
#include "NTEngine/Input/Manager.h"
#include <dinput.h>
#include "Input/src/ManagerImpl.h"

namespace NTEngine {
namespace Input {

BOOL CALLBACK ManagerImpl::countJoysticksCallBack( const DIDEVICEINSTANCE* instance, void* self ) {
	static_cast< ManagerImpl* >( self )->checkDevice( instance );
	return DIENUM_CONTINUE;
}

BOOL CALLBACK ManagerImpl::createJoysticksCallBack( const DIDEVICEINSTANCE* instance, void* self ) {
	return static_cast< ManagerImpl* >( self )->createDevice( instance );
}

ManagerImpl* g_ManagerImpl = NULL;

Manager::Manager() {
	ASSERT( Core::isMainThread() && "you must call from MAIN thread" );
}

Manager Manager::instance() {
	return Manager();
}

Mouse Manager::mouse() const {
	return Mouse();
}

Keyboard Manager::keyboard() const {
	return Keyboard();
}

Joystick Manager::joystick(int user) const {
	return Joystick( g_ManagerImpl->joystick( user ) );
}

int Manager::numJoysticks() const {
	return g_ManagerImpl->numJoysticks();
}

void Manager::update() {
	g_ManagerImpl->update();
}

void Manager::create( void* hInst, void* hWnd, int numJoys, int joyAxisMargin ) {
	HARD_ASSERT( g_ManagerImpl == 0 );
	g_ManagerImpl = NEW ManagerImpl(
		static_cast< HINSTANCE >( hInst ),
		static_cast< HWND >( hWnd ),
		numJoys, joyAxisMargin );
}

void Manager::destroy() {
	SAFE_DELETE( g_ManagerImpl );
}

} // namespace Input
} // namespace NTEngine
// EOF